<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">任务定义</ui:define>
    <ui:define name="content">
        <h:form>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton value="批量模式"
                                         icon="fa fa-list-ul"
                                         actionListener="#{scheduleDefinitionListBean.changeModeToBatch}"
                                         update="@form"
                                         process="@this"
                                         rendered="#{scheduleDefinitionListBean.isNotBatch()}"/>

                        <p:commandButton value="常规模式" icon="fa fa-file"
                                         actionListener="#{scheduleDefinitionListBean.changeModeToNormal}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{scheduleDefinitionListBean.isBatch()}"/>

                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"
                                         rendered="#{security:areAllGranted('DICTIONARY_SEARCH')}"/>

                        <p:columnToggler datasource="scheduleDataTable" trigger="toggler"
                                         rendered="#{security:areAllGranted('DICTIONARY_SEARCH')}"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         rendered="#{scheduleDefinitionListBean.isNormal() and security:areAllGranted('DICTIONARY_SEARCH')}"/>


                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{scheduleDefinitionListBean.onReset}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{scheduleDefinitionListBean.isNormal() and security:areAllGranted('DICTIONARY_SEARCH')}"/>
                        <p:commandButton value="启用" icon="fa fa-play"
                                         actionListener="#{scheduleDefinitionListBean.onBatchEnable}"
                                         update="@form"
                                         rendered="#{scheduleDefinitionListBean.isBatch() and security:areAllGranted('DICTIONARY_ENABLE')}"/>
                        <p:commandButton value="禁用" icon="fa fa-warning"
                                         actionListener="#{scheduleDefinitionListBean.onBatchDisable}"
                                         update="@form"
                                         rendered="#{scheduleDefinitionListBean.isBatch() and security:areAllGranted('DICTIONARY_DISABLE')}"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         rendered="#{scheduleDefinitionListBean.isBatch() and security:areAllGranted('DICTIONARY_EXPORT')}"
                                         ajax="false">
                            <p:dataExporter type="xls" target="scheduleDataTable" fileName="export"/>
                        </p:commandButton>
                        <p:commandButton icon="fa fa-plus" value="新增"
                                         action="#{scheduleDefinitionListBean.onAdd}"
                                         rendered="#{scheduleDefinitionListBean.isNormal() and security:areAllGranted('DICTIONARY_ADD')}">
                            <f:setPropertyActionListener value="/views/system/schedule/definition/list.xhtml"
                                                         target="#{currentUserBean.back}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">

                                <p:outputLabel for="taskName" value="任务名称"/>
                                <p:inputText id="taskName" value="#{scheduleDefinitionListBean.$.taskName}"/>

                                <p:outputLabel for="taskGroup" value="任务分组"/>
                                <p:selectOneMenu id="taskGroup"
                                                 value="#{scheduleDefinitionListBean.$.taskGroup}"
                                                 filter="true"
                                                 filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{scheduleDefinitionListBean.dictionaries[DictionaryCode.SCHEDULE_TASK_GROUP]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="startType" value="启动方式"/>
                                <p:selectOneMenu id="startType"
                                                 value="#{scheduleDefinitionListBean.$.startType}"
                                                 filter="true"
                                                 filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{scheduleDefinitionListBean.dictionaries[DictionaryCode.SCHEDULE_START_TYPE]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="executeType" value="执行方式"/>
                                <p:selectOneMenu id="executeType"
                                                 value="#{scheduleDefinitionListBean.$.executeType}"
                                                 filter="true"
                                                 filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{scheduleDefinitionListBean.dictionaries[DictionaryCode.SCHEDULE_EXECUTE_TYPE]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="enable" value="是否启用"/>
                                <p:selectOneMenu id="enable" value="#{scheduleDefinitionListBean.$.enable}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="是" itemValue="true"/>
                                    <f:selectItem itemLabel="否" itemValue="false"/>
                                </p:selectOneMenu>


                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="scheduleDataTable"
                                         style="width: 100%"
                                         var="schedule"
                                         value="#{scheduleDefinitionListBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{scheduleDefinitionListBean.selectedRecords}"
                                         resizableColumns="true"
                                         rendered="#{security:areAllGranted('DICTIONARY_SEARCH')}">

                                <p:column headerText="操作" rendered="#{scheduleDefinitionListBean.isNotBatch()}">
                                    <p:splitButton icon="fa fa-eye"
                                                   action="#{scheduleDefinitionListBean.onEdit(dictionary.id)}"
                                                   process="@this">
                                        <f:setPropertyActionListener
                                                value="/views/system/schedule/definition/list.xhtml"
                                                target="#{currentUserBean.back}"/>
                                        <p:menuitem value="启用" icon="fa fa-play"
                                                    action="#{scheduleDefinitionListBean.onEnable(schedule.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{!schedule.enable and security:areAllGranted('DICTIONARY_ENABLE')}"/>
                                        <p:menuitem value="禁用" icon="fa fa-warning"
                                                    actionListener="#{scheduleDefinitionListBean.onDisable(dictionary.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{schedule.enable and security:areAllGranted('DICTIONARY_DISABLE')}">
                                        </p:menuitem>
                                    </p:splitButton>
                                </p:column>
                                <p:column selectionMode="multiple" style="width:16px;text-align:center"
                                          rendered="#{scheduleDefinitionListBean.isBatch()}"/>
                                <p:column headerText="任务名称">
                                    <h:outputText value="#{schedule.taskName}"/>
                                </p:column>
                                <p:column headerText="任务分组">
                                    <h:outputText
                                            value="#{scheduleDefinitionListBean.translate(DictionaryCode.SCHEDULE_TASK_GROUP,schedule.taskGroup)}"/>
                                </p:column>
                                <p:column headerText="启动方式">
                                    <h:outputText
                                            value="#{scheduleDefinitionListBean.translate(DictionaryCode.SCHEDULE_START_TYPE,schedule.startType)}"/>
                                </p:column>
                                <p:column headerText="执行方式">
                                    <h:outputText
                                            value="#{scheduleDefinitionListBean.translate(DictionaryCode.SCHEDULE_EXECUTE_TYPE,schedule.executeType)}"/>
                                </p:column>
                                <p:column headerText="CRON表达式">
                                    <h:outputText value="#{schedule.cron}"/>
                                </p:column>
                                <p:column headerText="是否启用">
                                    <h:outputText value="#{schedule.enable ? '是' : '否'}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
